﻿using System.Collections.Generic;
using System.Linq;

namespace AzureDiagMon.Common.Algorithms.FragmentedRanges
{
    public abstract class ResolverStrategy : IFragmentedRangeResolverStrategy
    {
        protected abstract IFragmentedRangeSection GetNextSectionInternal(IFragmentedRange fragmentedRange, IEnumerable<IFragmentedRangeSection> emptySections);

        #region Implementation of IFragmentedRangeResolverStrategy

        public IFragmentedRangeSection GetNextSection(IFragmentedRange fragmentedRange)
        {
            var emptySections = fragmentedRange.GetEmptySections();
            if (emptySections.Count() == 0)
                return null;

            return GetNextSectionInternal(fragmentedRange, emptySections);
        }

        #endregion
        
    }
}